#include "wxsimagetreeeditordlg.h"

#include <wx/font.h>
#include <wx/intl.h>
#include <wx/string.h>

#include <wx/msgdlg.h>
#include "../properties/wxsimagelisteditordlg.h"

const long wxsImageTreeEditorDlg::ID_STATICTEXT1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_TREECTRL1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON2 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT3 = wxNewId();
const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON3 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT4 = wxNewId();
const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON4 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT5 = wxNewId();
const long wxsImageTreeEditorDlg::ID_BUTTON3 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT6 = wxNewId();
const long wxsImageTreeEditorDlg::ID_CHECKBOX1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_IMAGEBUTTON5 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT11 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT12 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT13 = wxNewId();
const long wxsImageTreeEditorDlg::ID_COMBOBOX1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT7 = wxNewId();
const long wxsImageTreeEditorDlg::ID_COMBOBOX2 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT8 = wxNewId();
const long wxsImageTreeEditorDlg::ID_COMBOBOX3 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT9 = wxNewId();
const long wxsImageTreeEditorDlg::ID_COMBOBOX4 = wxNewId();
const long wxsImageTreeEditorDlg::ID_STATICTEXT10 = wxNewId();
const long wxsImageTreeEditorDlg::ID_BUTTON1 = wxNewId();
const long wxsImageTreeEditorDlg::ID_BUTTON2 = wxNewId();

BEGIN_EVENT_TABLE( wxsImageTreeEditorDlg, wxDialog )
END_EVENT_TABLE()

wxsImageTreeEditorDlg::wxsImageTreeEditorDlg( wxWindow *parent ) {
  wxBoxSizer* BoxSizer4;
  wxBoxSizer* BoxSizer6;
  wxBoxSizer* BoxSizer5;
  wxBoxSizer* BoxSizer10;
  wxBoxSizer* BoxSizer7;
  wxBoxSizer* BoxSizer8;
  wxBoxSizer* BoxSizer13;
  wxBoxSizer* BoxSizer2;
  wxBoxSizer* BoxSizer11;
  wxBoxSizer* BoxSizer12;
  wxGridSizer* GridSizer1;
  wxBoxSizer* BoxSizer1;
  wxBoxSizer* BoxSizer9;
  wxBoxSizer* BoxSizer3;
  Create( parent, wxID_ANY, _T( "Tree Item Editor" ), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE, _T( "wxID_ANY" ) );
  wxFont thisFont( 8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, _T( "Arial" ), wxFONTENCODING_DEFAULT );
  SetFont( thisFont );
  BoxSizer1 = new wxBoxSizer( wxVERTICAL );
  BoxSizer2 = new wxBoxSizer( wxHORIZONTAL );
  StaticText1 = new wxStaticText( this, ID_STATICTEXT1, _T( "Edit Tree Items" ), wxPoint( 0, 0 ), wxSize( 400, 20 ), wxST_NO_AUTORESIZE | wxALIGN_CENTRE, _T( "ID_STATICTEXT1" ) );
  wxFont StaticText1Font( 10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, _T( "Arial" ), wxFONTENCODING_DEFAULT );
  StaticText1->SetFont( StaticText1Font );
  BoxSizer2->Add( StaticText1, 1, wxEXPAND, 0 );
  BoxSizer1->Add( BoxSizer2, 0, wxEXPAND, 0 );
  BoxSizer3 = new wxBoxSizer( wxHORIZONTAL );
  BoxSizer5 = new wxBoxSizer( wxHORIZONTAL );
  StaticBoxSizer1 = new wxStaticBoxSizer( wxHORIZONTAL, this, _T( "tree-name" ) );
  Tree1 = new wxTreeCtrl( this, ID_TREECTRL1, wxPoint( 2, 36 ), wxSize( 246, 359 ), wxTR_EDIT_LABELS | wxTR_DEFAULT_STYLE, wxDefaultValidator, _T( "ID_TREECTRL1" ) );
  StaticBoxSizer1->Add( Tree1, 0, wxALIGN_BOTTOM, 5 );
  BoxSizer5->Add( StaticBoxSizer1, 0, wxALIGN_BOTTOM, 5 );
  BoxSizer3->Add( BoxSizer5, 0, wxALL | wxEXPAND, 0 );
  BoxSizer6 = new wxBoxSizer( wxHORIZONTAL );
  StaticBoxSizer2 = new wxStaticBoxSizer( wxVERTICAL, this, _T( "Attributes" ) );
  BoxSizer7 = new wxBoxSizer( wxHORIZONTAL );
  bAddItem = new wxBitmapButton( this, ID_IMAGEBUTTON1, wxNullBitmap, wxPoint( 256, 36 ), wxSize( 24, 23 ), wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_IMAGEBUTTON1" ) );
  bAddItem->SetToolTip( _T( "Add A New Item" ) );
  BoxSizer7->Add( bAddItem, 0, wxALIGN_BOTTOM, 5 );
  StaticText2 = new wxStaticText( this, wxID_ANY, _T( "Add Item" ), wxPoint( 290, 40 ), wxDefaultSize, 0, _T( "wxID_ANY" ) );
  BoxSizer7->Add( StaticText2, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer7, 0, wxEXPAND, 0 );
  BoxSizer8 = new wxBoxSizer( wxHORIZONTAL );
  bAddSubItem = new wxBitmapButton( this, ID_IMAGEBUTTON2, wxNullBitmap, wxPoint( 256, 66 ), wxSize( 24, 23 ), wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_IMAGEBUTTON2" ) );
  bAddSubItem->SetToolTip( _T( "Add A New Child" ) );
  BoxSizer8->Add( bAddSubItem, 0, wxALIGN_BOTTOM, 5 );
  StaticText3 = new wxStaticText( this, ID_STATICTEXT3, _T( "Add Sub-Item" ), wxPoint( 290, 70 ), wxDefaultSize, 0, _T( "ID_STATICTEXT3" ) );
  BoxSizer8->Add( StaticText3, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer8, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer9 = new wxBoxSizer( wxHORIZONTAL );
  bDelItem = new wxBitmapButton( this, ID_IMAGEBUTTON3, wxNullBitmap, wxPoint( 256, 96 ), wxSize( 24, 23 ), wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_IMAGEBUTTON3" ) );
  bDelItem->SetToolTip( _T( "Delete Current Item" ) );
  BoxSizer9->Add( bDelItem, 0, wxALIGN_BOTTOM, 5 );
  StaticText4 = new wxStaticText( this, ID_STATICTEXT4, _T( "Delete Current Item" ), wxPoint( 290, 100 ), wxDefaultSize, 0, _T( "ID_STATICTEXT4" ) );
  BoxSizer9->Add( StaticText4, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer9, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer10 = new wxBoxSizer( wxHORIZONTAL );
  bDelAllItems = new wxBitmapButton( this, ID_IMAGEBUTTON4, wxNullBitmap, wxPoint( 256, 126 ), wxSize( 24, 23 ), wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_IMAGEBUTTON4" ) );
  bDelAllItems->SetToolTip( _T( "Delete All Items" ) );
  BoxSizer10->Add( bDelAllItems, 0, wxALIGN_BOTTOM, 5 );
  StaticText5 = new wxStaticText( this, ID_STATICTEXT5, _T( "Delete All Items" ), wxPoint( 290, 130 ), wxDefaultSize, 0, _T( "ID_STATICTEXT5" ) );
  BoxSizer10->Add( StaticText5, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer10, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer11 = new wxBoxSizer( wxHORIZONTAL );
  bItemColor = new wxButton( this, ID_BUTTON3, _T( "C" ), wxPoint( 256, 156 ), wxSize( 24, 24 ), 0, wxDefaultValidator, _T( "ID_BUTTON3" ) );
  wxFont bItemColorFont( 10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, _T( "Arial Black" ), wxFONTENCODING_DEFAULT );
  bItemColor->SetFont( bItemColorFont );
  bItemColor->SetToolTip( _T( "Set Item Text Color" ) );
  BoxSizer11->Add( bItemColor, 0, wxALIGN_BOTTOM, 5 );
  StaticText6 = new wxStaticText( this, ID_STATICTEXT6, _T( "Set Item Text Color" ), wxPoint( 290, 160 ), wxDefaultSize, 0, _T( "ID_STATICTEXT6" ) );
  BoxSizer11->Add( StaticText6, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer11, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer12 = new wxBoxSizer( wxHORIZONTAL );
  cxItemBold = new wxCheckBox( this, ID_CHECKBOX1, _T( " Set Item Text Bold" ), wxPoint( 262, 192 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_CHECKBOX1" ) );
  cxItemBold->SetValue( false );
  cxItemBold->SetToolTip( _T( "Set Item Text Bold" ) );
  BoxSizer12->Add( cxItemBold, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer12, 0, wxTOP | wxEXPAND, 5 );
  BoxSizer13 = new wxBoxSizer( wxHORIZONTAL );
  bEditItem = new wxBitmapButton( this, ID_IMAGEBUTTON5, wxNullBitmap, wxPoint( 256, 216 ), wxSize( 24, 23 ), wxBU_AUTODRAW, wxDefaultValidator, _T( "ID_IMAGEBUTTON5" ) );
  bEditItem->SetToolTip( _T( "Start Editor On Current Item" ) );
  BoxSizer13->Add( bEditItem, 0, wxALIGN_BOTTOM, 5 );
  StaticText11 = new wxStaticText( this, ID_STATICTEXT11, _T( "Edit Current Item" ), wxPoint( 290, 220 ), wxDefaultSize, 0, _T( "ID_STATICTEXT11" ) );
  BoxSizer13->Add( StaticText11, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  StaticBoxSizer2->Add( BoxSizer13, 0, wxTOP | wxEXPAND, 5 );
  GridSizer1 = new wxGridSizer( 5, 2, 0, 0 );
  StaticText12 = new wxStaticText( this, ID_STATICTEXT12, _T( "Image-List" ), wxPoint( 256, 272 ), wxDefaultSize, 0, _T( "ID_STATICTEXT12" ) );
  GridSizer1->Add( StaticText12, 0, wxALIGN_CENTER_VERTICAL, 5 );
  StaticText13 = new wxStaticText( this, ID_STATICTEXT13, _T( "Label" ), wxPoint( 310, 272 ), wxSize( 82, 14 ), wxST_NO_AUTORESIZE, _T( "ID_STATICTEXT13" ) );
  StaticText13->SetForegroundColour( wxColour( 0, 0, 255 ) );
  GridSizer1->Add( StaticText13, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5 );
  cbNormal = new wxBitmapComboBox( this, ID_COMBOBOX1, wxEmptyString, wxPoint( 256, 296 ), wxSize( 48, 22 ), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T( "ID_COMBOBOX1" ) );
  GridSizer1->Add( cbNormal, 0, wxTOP | wxEXPAND, 3 );
  StaticText7 = new wxStaticText( this, ID_STATICTEXT7, _T( "Normal Image" ), wxPoint( 310, 300 ), wxDefaultSize, 0, _T( "ID_STATICTEXT7" ) );
  GridSizer1->Add( StaticText7, 0, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 3 );
  cbSelected = new wxBitmapComboBox( this, ID_COMBOBOX2, wxEmptyString, wxPoint( 256, 326 ), wxSize( 48, 22 ), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T( "ID_COMBOBOX2" ) );
  GridSizer1->Add( cbSelected, 0, wxTOP | wxEXPAND, 3 );
  StaticText8 = new wxStaticText( this, ID_STATICTEXT8, _T( "Selected Image" ), wxPoint( 310, 330 ), wxDefaultSize, 0, _T( "ID_STATICTEXT8" ) );
  GridSizer1->Add( StaticText8, 0, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 3 );
  cbExpanded = new wxBitmapComboBox( this, ID_COMBOBOX3, wxEmptyString, wxPoint( 256, 356 ), wxSize( 48, 22 ), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T( "ID_COMBOBOX3" ) );
  GridSizer1->Add( cbExpanded, 0, wxTOP | wxEXPAND, 3 );
  StaticText9 = new wxStaticText( this, ID_STATICTEXT9, _T( "Expanded Image" ), wxPoint( 310, 360 ), wxDefaultSize, 0, _T( "ID_STATICTEXT9" ) );
  GridSizer1->Add( StaticText9, 0, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 3 );
  cbSelExpanded = new wxBitmapComboBox( this, ID_COMBOBOX4, wxEmptyString, wxPoint( 256, 386 ), wxSize( 48, 22 ), 0, NULL, wxCB_READONLY, wxDefaultValidator, _T( "ID_COMBOBOX4" ) );
  GridSizer1->Add( cbSelExpanded, 0, wxTOP | wxEXPAND, 3 );
  StaticText10 = new wxStaticText( this, ID_STATICTEXT10, _T( "Sel+Exp Image" ), wxPoint( 310, 390 ), wxDefaultSize, 0, _T( "ID_STATICTEXT10" ) );
  GridSizer1->Add( StaticText10, 0, wxTOP | wxLEFT | wxALIGN_CENTER_VERTICAL, 3 );
  StaticBoxSizer2->Add( GridSizer1, 0, wxTOP | wxALIGN_LEFT, 5 );
  BoxSizer6->Add( StaticBoxSizer2, 0, wxLEFT | wxEXPAND, 5 );
  BoxSizer3->Add( BoxSizer6, 0, wxALL | wxEXPAND, 0 );
  BoxSizer1->Add( BoxSizer3, 0, wxALL | wxEXPAND, 0 );
  BoxSizer4 = new wxBoxSizer( wxHORIZONTAL );
  bOK = new wxButton( this, ID_BUTTON1, _T( "OK" ), wxPoint( 48, 440 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON1" ) );
  bOK->SetDefault();
  BoxSizer4->Add( bOK, 0, wxALIGN_BOTTOM, 5 );
  BoxSizer4->Add( -1, -1, 1, wxLEFT | wxEXPAND, 5 );
  bCancel = new wxButton( this, ID_BUTTON2, _T( "Cancel" ), wxPoint( 280, 440 ), wxDefaultSize, 0, wxDefaultValidator, _T( "ID_BUTTON2" ) );
  BoxSizer4->Add( bCancel, 0, wxLEFT | wxALIGN_BOTTOM, 5 );
  BoxSizer1->Add( BoxSizer4, 0, wxTOP | wxEXPAND, 0 );
  SetSizer( BoxSizer1 );
  static const char *ImageList1_0_XPM[] = {
    "16 16 3 1",
    ". c Black",
    "X c #00C000",
    "_ c None",
    "________......._",
    "________.XXXXX._",
    "___..___.XXXXX._",
    "___..___.XXXXX._",
    "_......_.XXXXX._",
    "_......_.XXXXX._",
    "___..___.XXXXX._",
    "___..___.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XX.XX._",
    "________.X._.X._",
    "________..___.._",
    "................"
  };
  static const char *ImageList1_1_XPM[] = {
    "16 16 4 1",
    "o c Black",
    ". c #000080",
    "X c #0000FF",
    "_ c None",
    "________......._",
    "________.XXXXX._",
    "___oo___.XXXXX._",
    "___oo___.XXXXX._",
    "_oooooo_.XXXXX._",
    "_oooooo_.XXXXX._",
    "___oo___.XXXXX._",
    "___oo___.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XX.XX._",
    "________.X._.X._",
    "________..___.._",
    "oooooooooooooooo"
  };
  static const char *ImageList1_2_XPM[] = {
    "16 16 3 1",
    ". c Black",
    "_ c None",
    "X c #FF4040",
    "________......._",
    "________.XXXXX._",
    "__.___._.XXXXX._",
    "__.._.._.XXXXX._",
    "___...__.XXXXX._",
    "____.___.XXXXX._",
    "___...__.XXXXX._",
    "__.._.._.XXXXX._",
    "__.___._.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XXXXX._",
    "________.XX.XX._",
    "________.X._.X._",
    "________..___.._",
    "................"
  };
  static const char *ImageList1_3_XPM[] = {
    "16 16 22 1",
    "4 c Black",
    "3 c #A5AEBD",
    "= c #5478B4",
    "1 c #95A3BB",
    "O c #9AA7BC",
    ": c #758EB7",
    "$ c #6986B6",
    "# c #4971B2",
    "* c #8A9CBA",
    "X c #8598B9",
    "o c #ABB2BE",
    "; c #7F95B9",
    "- c #4E74B3",
    "2 c #A0ABBC",
    "+ c #6F8AB7",
    "_ c None",
    ". c #B5B9BF",
    "@ c #3E69B1",
    "< c #90A0BA",
    "> c #6483B5",
    ", c #5A7BB4",
    "& c #5F7FB5",
    "________________",
    "____.Xo______OO_",
    "____+@#.____$@&_",
    "____*@@X__.=@=o_",
    "_____-@-_.=@=.__",
    "_____;@@X=@=.___",
    "_____.#@@@$.____",
    "______:@@>______",
    "_____:@@@+______",
    "___.,@#&@@._____",
    "__o=@=oO@@<_____",
    "_1#@=._.@@-_____",
    "*@@$____>@@2____",
    ":#*_____3#,.____",
    "________________",
    "4444444444444444"
  };
  static const char *ImageList1_4_XPM[] = {
    "16 16 2 1",
    ". c Black",
    "_ c None",
    "________________",
    "______..________",
    "______..._______",
    "_____...._______",
    "_____._...______",
    "____.._...______",
    "____.___..______",
    "___..___..._____",
    "___._____.._____",
    "___.........____",
    "__.._____...____",
    "__._______...___",
    "_.._______...___",
    "_....___......._",
    "________________",
    "................"
  };
  ImageList1 = new wxImageList( 16, 16, 6 );
  ImageList1->Add( wxBitmap( ImageList1_0_XPM ) );
  ImageList1->Add( wxBitmap( ImageList1_1_XPM ) );
  ImageList1->Add( wxBitmap( ImageList1_2_XPM ) );
  ImageList1->Add( wxBitmap( ImageList1_3_XPM ) );
  ImageList1->Add( wxBitmap( ImageList1_4_XPM ) );
  ColourDialog1 = new wxColourDialog( this );
  BoxSizer1->Fit( this );
  BoxSizer1->SetSizeHints( this );
  Connect( ID_TREECTRL1, wxEVT_COMMAND_TREE_SEL_CHANGED, wxTreeEventHandler( wxsImageTreeEditorDlg::OnTreeCtrl1SelectionChanged ) );
  bAddItem->SetBitmapLabel( ImageList1->GetBitmap( 0 ) );
  Connect( ID_IMAGEBUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbAddItemClick ) );
  bAddSubItem->SetBitmapLabel( ImageList1->GetBitmap( 1 ) );
  Connect( ID_IMAGEBUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbAddSubItemClick ) );
  bDelItem->SetBitmapLabel( ImageList1->GetBitmap( 2 ) );
  Connect( ID_IMAGEBUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbDelItemClick ) );
  bDelAllItems->SetBitmapLabel( ImageList1->GetBitmap( 3 ) );
  Connect( ID_IMAGEBUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbDelAllItemsClick ) );
  Connect( ID_BUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbItemColorClick ) );
  Connect( ID_CHECKBOX1, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OncxItemBoldClick ) );
  bEditItem->SetBitmapLabel( ImageList1->GetBitmap( 4 ) );
  Connect( ID_IMAGEBUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbEditItemClick ) );
  Connect( ID_COMBOBOX1, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( wxsImageTreeEditorDlg::OncbNormalSelect ) );
  Connect( ID_COMBOBOX2, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( wxsImageTreeEditorDlg::OncbSelectedSelect ) );
  Connect( ID_COMBOBOX3, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( wxsImageTreeEditorDlg::OncbExpandedSelect ) );
  Connect( ID_COMBOBOX4, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( wxsImageTreeEditorDlg::OncbSelExpandedSelect ) );
  Connect( ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbOKClick ) );
  Connect( ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxsImageTreeEditorDlg::OnbCancelClick ) );
}

wxsImageTreeEditorDlg::~wxsImageTreeEditorDlg() {
}

bool wxsImageTreeEditorDlg::Execute( wxArrayString &aItems ) {
  int i, n;
  int jv, j1, j2, j3, j4;
  wxColor jc;
  bool jb;
  wxString jt;
  wxTreeItemId jp[32];
  wxString ss, tt;
  wxTreeItemId root;
  wxTreeItemId item;
  wxBitmap bmp;
  wxsImageList *ilist;
  n = aItems.GetCount();
  m_sTreeName  = _T( "<unknown>" );
  m_sImageName = _T( "<none>" );
  if( n >= 1 ) {
    m_sTreeName  = aItems.Item( 0 );
  }
  if( n >= 2 ) {
    m_sImageName = aItems.Item( 1 );
  }
  ss = _T( "Tree Control: " ) + m_sTreeName;
  StaticBoxSizer1->GetStaticBox()->SetLabel( ss );
  ss = m_sImageName;
  StaticText13->SetLabel( ss );
  Tree1->DeleteAllItems();
  m_imageList.RemoveAll();
  ilist = ( wxsImageList * ) wxsImageListEditorDlg::FindTool( NULL, m_sImageName );
  if( ilist != NULL ) {
    ilist->GetImageList( m_imageList );
  }
  SetImageList( m_imageList );
  n = aItems.GetCount();
  for( i = 2; i < n; i++ ) {
    ss = aItems.Item( i );
    ParseTreeItem( ss, jv, jc, jb, j1, j2, j3, j4, jt );
    if( jv == 0 ) {
      item = Tree1->AddRoot( jt );
    } else
    { item = Tree1->AppendItem( jp[jv - 1], jt ); }
    jp[jv] = item;
    if( jc.IsOk() ) {
      Tree1->SetItemTextColour( item, jc );
    }
    Tree1->SetItemBold( item, jb );
    Tree1->SetItemImage( item, j1, wxTreeItemIcon_Normal );
    Tree1->SetItemImage( item, j2, wxTreeItemIcon_Selected );
    Tree1->SetItemImage( item, j3, wxTreeItemIcon_Expanded );
    Tree1->SetItemImage( item, j4, wxTreeItemIcon_SelectedExpanded );
  }
  Tree1->ExpandAll();
  n = ShowModal();
  if( n == wxOK ) {
    aItems.Clear();
    aItems.Add( m_sTreeName );
    aItems.Add( m_sImageName );
    root = Tree1->GetRootItem();
    if( root.IsOk() ) {
      EncodeTreeItems( root, 0, aItems );
    }
  }
  return ( n == wxOK );
}

void wxsImageTreeEditorDlg::SetImageList( wxImageList &inImageList ) {
  int         i, n;
  wxString    ss, tt;
  wxBitmap    bmp;
  Tree1->SetImageList( &inImageList );
  n = inImageList.GetImageCount();
  if( n <= 0 ) {
    cbNormal->Enable( false );
    cbSelected->Enable( false );
    cbExpanded->Enable( false );
    cbSelExpanded->Enable( false );
  } else {
    cbNormal->Enable( true );
    cbSelected->Enable( true );
    cbExpanded->Enable( true );
    cbSelExpanded->Enable( true );
  }
  cbNormal->Clear();
  cbSelected->Clear();
  cbExpanded->Clear();
  cbSelExpanded->Clear();
  ss = _T( "<none>" );
  cbNormal->Append( ss );
  cbSelected->Append( ss );
  cbExpanded->Append( ss );
  cbSelExpanded->Append( ss );
  for( i = 0; i < n; i++ ) {
    ss.Printf( wxT( "%d" ), i );
    bmp = inImageList.GetBitmap( i );
    cbNormal->Append( ss, bmp );
    cbSelected->Append( ss, bmp );
    cbExpanded->Append( ss, bmp );
    cbSelExpanded->Append( ss, bmp );
  }
  cbNormal->SetSelection( 0 );
  cbSelected->SetSelection( 0 );
  cbExpanded->SetSelection( 0 );
  cbSelExpanded->SetSelection( 0 );
}

void wxsImageTreeEditorDlg::OnbAddItemClick( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n = Tree1->GetCount();
  current = Tree1->GetSelection();
  if( n <= 0 ) {
    current.Unset();
    AddItem( current );
  } else if( ! current.IsOk() ) {
    current = Tree1->GetRootItem();
    AddItem( current );
  } else {
    current = Tree1->GetItemParent( current );
    AddItem( current );
  }
}

void wxsImageTreeEditorDlg::OnbAddSubItemClick( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n = Tree1->GetCount();
  current = Tree1->GetSelection();
  if( n <= 0 ) {
    current.Unset();
    AddItem( current );
  } else if( ! current.IsOk() ) {
    current = Tree1->GetRootItem();
    AddItem( current );
  } else {
    AddItem( current );
  }
  Tree1->Expand( current );
}

void wxsImageTreeEditorDlg::AddItem( wxTreeItemId &inParent ) {
  int             n;
  wxString        ss, tt;
  wxTreeItemId    parent, current;
  wxColour        cc;
  bool            b;
  n = Tree1->GetCount();
  if( n <= 0 ) {
    ss = _T( "root" );
    current = Tree1->AddRoot( ss );
  } else if( ! inParent.IsOk() ) {
    ss.Printf( _T( "item %d" ), n );
    parent = Tree1->GetRootItem();
    current = Tree1->AppendItem( parent, ss );
  } else {
    ss.Printf( _T( "item %d" ), n );
    current = Tree1->AppendItem( inParent, ss );
  }
  if( ! current.IsOk() ) {
    return;
  }
  cc = bItemColor->GetForegroundColour();
  Tree1->SetItemTextColour( current, cc );
  b = cxItemBold->GetValue();
  Tree1->SetItemBold( current, b );
  n = cbNormal->GetSelection() - 1;
  if( n >= 0 ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Normal );
  }
  n = cbSelected->GetSelection() - 1;
  if( n >= 0 ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Selected );
  }
  n = cbExpanded->GetSelection() - 1;
  if( n >= 0 ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Expanded );
  }
  n = cbSelExpanded->GetSelection() - 1;
  if( n >= 0 ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_SelectedExpanded );
  }
  Tree1->Refresh();
}

void wxsImageTreeEditorDlg::OnbDelItemClick( M_Code_unused wxCommandEvent &event ) {
  wxTreeItemId    current;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->Delete( current );
  }
}

void wxsImageTreeEditorDlg::OnbDelAllItemsClick( M_Code_unused wxCommandEvent &event ) {
  int         n;
  wxString    ss;
  n = wxMessageBox( _T( "Delete ALL Items In Tree?" ), _T( "Clear" ), wxYES_NO );
  if( n == wxYES ) {
    Tree1->DeleteAllItems();
  }
}

void wxsImageTreeEditorDlg::OnbItemColorClick( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxColourData    cd;
  wxColour        cc;
  wxTreeItemId    current;
  n = ColourDialog1->ShowModal();
  if( n != wxID_OK ) {
    return;
  }
  cd = ColourDialog1->GetColourData();
  cc = cd.GetColour();
  bItemColor->SetForegroundColour( cc );
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemTextColour( current, cc );
  }
}

void wxsImageTreeEditorDlg::OncxItemBoldClick( M_Code_unused wxCommandEvent &event ) {
  bool            b;
  wxTreeItemId    current;
  b = cxItemBold->GetValue();
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemBold( current, b );
  }
}

void wxsImageTreeEditorDlg::OnbEditItemClick( M_Code_unused wxCommandEvent &event ) {
  wxTreeItemId    current;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->EditLabel( current );
  }
}

void wxsImageTreeEditorDlg::OncbNormalSelect( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n  = cbNormal->GetSelection();
  n -= 1;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Normal );
  }
}

void wxsImageTreeEditorDlg::OncbSelectedSelect( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n  = cbSelected->GetSelection();
  n -= 1;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Selected );
  }
}

void wxsImageTreeEditorDlg::OncbExpandedSelect( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n  = cbExpanded->GetSelection();
  n -= 1;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_Expanded );
  }
}

void wxsImageTreeEditorDlg::OncbSelExpandedSelect( M_Code_unused wxCommandEvent &event ) {
  int             n;
  wxTreeItemId    current;
  n  = cbSelExpanded->GetSelection();
  n -= 1;
  current = Tree1->GetSelection();
  if( current.IsOk() ) {
    Tree1->SetItemImage( current, n, wxTreeItemIcon_SelectedExpanded );
  }
}


void wxsImageTreeEditorDlg::OnTreeCtrl1SelectionChanged( M_Code_unused wxTreeEvent &event ) {
  int             n;
  wxTreeItemId    current;
  wxColour        cc;
  bool            b;
  current = Tree1->GetSelection();
  if( ! current.IsOk() ) {
    return;
  }
  cc = Tree1->GetItemTextColour( current );
  bItemColor->SetForegroundColour( cc );
  b = Tree1->IsBold( current );
  cxItemBold->SetValue( b );
  n = Tree1->GetItemImage( current, wxTreeItemIcon_Normal );
  n += 1;
  cbNormal->SetSelection( n );
  n = Tree1->GetItemImage( current, wxTreeItemIcon_Selected );
  n += 1;
  cbSelected->SetSelection( n );
  n = Tree1->GetItemImage( current, wxTreeItemIcon_Expanded );
  n += 1;
  cbExpanded->SetSelection( n );
  n = Tree1->GetItemImage( current, wxTreeItemIcon_SelectedExpanded );
  n += 1;
  cbSelExpanded->SetSelection( n );
}


void wxsImageTreeEditorDlg::ParseTreeItem( wxString aSource, int &outLevel, wxColour &outColour, bool &outBold, int &outImage1, int &outImage2, int &outImage3, int &outImage4, wxString &outText ) {
  int         i, n;
  long        ll;
  wxString    ss, tt;
  ss = aSource;
  outLevel = 1;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      outLevel = ll;
    }
  }
  outColour.Set( wxT( "?" ) );
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    outColour.Set( tt );
  }
  n = 0;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      n = ll;
    }
  }
  outBold = ( n != 0 );
  outImage1 = -1;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      outImage1 = ll;
    }
  }
  outImage2 = -1;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      outImage2 = ll;
    }
  }
  outImage3 = -1;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      outImage3 = ll;
    }
  }
  outImage4 = -1;
  i  = ss.Find( wxT( "," ) );
  if( i != wxNOT_FOUND ) {
    tt = ss.Left( i );
    ss.erase( 0, i + 1 );
    if( tt.ToLong( &ll ) ) {
      outImage4 = ll;
    }
  }
  ss.Trim( true );
  ss.Trim( false );
  outText = ss;
}


void wxsImageTreeEditorDlg::EncodeTreeItems( wxTreeItemId inParent, int inLevel, wxArrayString &outList ) {
  int                 n;
  wxColour            cc;
  wxString            ss, tt;
  wxTreeItemId        child;
  wxTreeItemIdValue   cookie;
  ss = wxEmptyString;
  tt.Printf( wxT( "%d," ), inLevel );
  ss += tt;
  cc  = Tree1->GetItemTextColour( inParent );
  tt  = cc.GetAsString( wxC2S_HTML_SYNTAX );
  tt += wxT( "," );
  ss += tt;
  if( Tree1->IsBold( inParent ) ) {
    tt = wxT( "1," );
  } else {
    tt = wxT( "0," );
  }
  ss += tt;
  n = Tree1->GetItemImage( inParent, wxTreeItemIcon_Normal );
  tt.Printf( wxT( "%d," ), n );
  ss += tt;
  n = Tree1->GetItemImage( inParent, wxTreeItemIcon_Selected );
  tt.Printf( wxT( "%d," ), n );
  ss += tt;
  n = Tree1->GetItemImage( inParent, wxTreeItemIcon_Expanded );
  tt.Printf( wxT( "%d," ), n );
  ss += tt;
  n = Tree1->GetItemImage( inParent, wxTreeItemIcon_SelectedExpanded );
  tt.Printf( wxT( "%d," ), n );
  ss += tt;
  tt = Tree1->GetItemText( inParent );
  ss += tt;
  outList.Add( ss );
  child = Tree1->GetFirstChild( inParent, cookie );
  while( child.IsOk() ) {
    EncodeTreeItems( child, inLevel + 1, outList );
    child = Tree1->GetNextChild( inParent, cookie );
  }
}


void wxsImageTreeEditorDlg::OnbOKClick( M_Code_unused wxCommandEvent &event ) {
  EndModal( wxOK );
}


void wxsImageTreeEditorDlg::OnbCancelClick( M_Code_unused wxCommandEvent &event ) {
  EndModal( wxCANCEL );
}
